package com.ruoyi.system.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.ruoyi.system.domain.Vo.CmUserHtHty;
import com.ruoyi.system.domain.Vo.CmUserPiJ;
import com.ruoyi.system.domain.Vo.R;
import com.ruoyi.system.mapper.CmUserDangerMapper;
import com.ruoyi.system.mapper.CmUserPiJMapper;
import com.ruoyi.system.service.ICmUserHtclockinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.CmUserHtclockinMapper;
import com.ruoyi.system.domain.CmUserHtclockin;
//import com.ruoyi.system.service.ICmUserHtclockinService;
import com.ruoyi.common.core.text.Convert;

/**
 * 打卡统计Service业务层处理
 * 
 * @author pop404NotFound
 * @date 2021-11-20
 */
@Service
public class CmUserHtclockinServiceImpl implements ICmUserHtclockinService
{
    @Autowired
    private CmUserHtclockinMapper cmUserHtclockinMapper;

    @Autowired
    private CmUserPiJMapper cmUserPiJMapper;

    @Autowired
    private CmUserDangerMapper cmUserDangerMapper;

    /**
     * 查询打卡统计
     * 
     * @param id 打卡统计主键
     * @return 打卡统计
     */
    @Override
    public CmUserHtHty selectCmUserHtclockinById(Long id)
    {
        return cmUserHtclockinMapper.selectCmUserHtclockinById(id);
    }

    /**
     *  微信接口查询打卡记录
     * @param openid
     * @return list
     */
    public R selectWxCmUserHthtyOpenId(String openid){
        List<CmUserHtHty> cmUserHtHties = cmUserHtclockinMapper.selectWxCmUserHthtyOpenId(openid);
        if(cmUserHtHties!=null){
            return new R(200,"查询成功",cmUserHtHties);
        }else{
            return new R(200,"当前暂无数据");
        }

    }

    /**
     *  微信接口查询某日记录
     *  @param cmUserHtHty
     *  @return 集合
     */
    public R selectWxCmUserHtNowdate(CmUserHtHty cmUserHtHty,String Nowdate){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = simpleDateFormat.parse(Nowdate);
            cmUserHtHty.setNowdate(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        CmUserHtHty userHtHty = cmUserHtclockinMapper.selectWxCmUserHtNowdate(cmUserHtHty);
        if(userHtHty!=null){
            return new R(200,"查询成功",userHtHty);
        }
        return new R(202,"查询成功，数据为空");
    }

    /**
     * 查询打卡统计列表
     * 
     * @param cmUserHtclockin 打卡统计
     * @return 打卡统计
     */
    @Override
    public List<CmUserHtHty> selectCmUserHtclockinList(CmUserHtclockin cmUserHtclockin)
    {
        return cmUserHtclockinMapper.selectCmUserHtclockinList(cmUserHtclockin);
    }

    /**
     * 新增打卡统计
     * 
     * @param cmUserHtclockin 打卡统计
     * @return 结果
     */
    @Override
    public int insertCmUserHtclockin(CmUserHtclockin cmUserHtclockin)
    {
        return cmUserHtclockinMapper.insertCmUserHtclockin(cmUserHtclockin);
    }

    /**
     * 修改打卡统计
     * 
     * @param cmUserHtclockin 打卡统计
     * @return 结果
     */
    @Override
    public int updateCmUserHtclockin(CmUserHtclockin cmUserHtclockin)
    {
        return cmUserHtclockinMapper.updateCmUserHtclockin(cmUserHtclockin);
    }

    /**
     * 批量删除打卡统计
     * 
     * @param ids 需要删除的打卡统计主键
     * @return 结果
     */
    @Override
    public int deleteCmUserHtclockinByIds(String ids)
    {
        return cmUserHtclockinMapper.deleteCmUserHtclockinByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除打卡统计信息
     * 
     * @param id 打卡统计主键
     * @return 结果
     */
    @Override
    public int deleteCmUserHtclockinById(Long id)
    {
        return cmUserHtclockinMapper.deleteCmUserHtclockinById(id);
    }

    /**
     * 查询未打卡人员+日期
     *
     * @param cmUserPiJ
     * @return 结果
     */
    public List<CmUserPiJ> selectPijIndexList(CmUserPiJ cmUserPiJ){
        return cmUserPiJMapper.selectPijList(cmUserPiJ);
    }


}
